package com.example.task08.school;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Spring boot starter configuration.
 */
@Configuration
@ComponentScan("com.example.task08.school")
//@EnableConfigurationProperties(SchoolAutoConfig.class)
@ConditionalOnProperty(prefix = "example.task08.school", name = "enabled", havingValue = "true", matchIfMissing = true)
@RequiredArgsConstructor
public class SchoolAutoConfig implements EnvironmentAware {

    @Bean
    public Student getStudent(){
        return new Student();
    }

    @Bean
    public Klass getKlass(){

        return new Klass();
    }

    @Bean
    public School getSchool(){
        return new School();
    }

    @Override
    public void setEnvironment(Environment environment) {
        System.out.println("加载中...");
    }
}
